package com.yiwan.app.preventionsis.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.yiwan.app.preventionsis.R;
import com.yiwan.app.preventionsis.ui.ShowActivity;

public class FragmentMenu extends Fragment {

    private static ShowActivity activity;
    private View layout = null;
    private ImageView[] btnMenu = null;
    private static final int NOF_MENU = 7;

    public static FragmentMenu newInstance(ShowActivity act) {
        final FragmentMenu fShow = new FragmentMenu();
        activity = act;
        return fShow;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        layout = inflater.inflate(R.layout.fragment_menu, container, false);
        btnMenu = new ImageView[NOF_MENU];
        btnMenu[0] = (ImageView) layout.findViewById(R.id.menu_0);
        btnMenu[1] = (ImageView) layout.findViewById(R.id.menu_1);
        btnMenu[2] = (ImageView) layout.findViewById(R.id.menu_2);
        btnMenu[3] = (ImageView) layout.findViewById(R.id.menu_3);
        btnMenu[4] = (ImageView) layout.findViewById(R.id.menu_4);
        btnMenu[5] = (ImageView) layout.findViewById(R.id.menu_5);
        btnMenu[6] = (ImageView) layout.findViewById(R.id.menu_6);

        for (ImageView button : btnMenu) {
            button.setOnClickListener(new MyOnClickListener());
        }

        //Log.d("getSceenHeightInPix", "" + ScreenResolution.getSceenHeightInPix());
        return layout;
    }

    private class MyOnClickListener implements OnClickListener {

        @Override
        public void onClick(View v) {
            for (int i = 0; i < btnMenu.length; i++) {
                if (v == btnMenu[i]) {
                    activity.pageToIndex(i);
                }
            }
        }
    }
}
